<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>插件测试</title>
    <script src="cordova.js"></script>
</head>

<body>
    <div id="app">
        <div>
            <div>设备ID:</div>
            <div><input type="text" placeholder="deviceid" v-model="did" style="width: 200px;"></div>
        </div>
        <div>
            <div>频率:</div>
            <div><input type="number" placeholder="frequenecy" v-model.number="freq" style="width: 200px;"></div>
        </div>
        <div><button @click="add">加法测试</button></div>
        <div>{{resadd}}</div>
        <div><button @click="init">init</button></div>
        <div>{{resinit}}</div>
        <div><button @click="openSerialPort">openSerialPort</button></div>
        <div>{{resopenSerialPort}}</div>
        <div><button @click="closeSerialPort">closeSerialPort</button></div>
        <div>{{rescloseSerialPort}}</div>
        <div><button @click="scanWSDevice">scanWSDevice</button></div>
        <div>{{resscanWSDevice}}</div>
        <div><button @click="bindWSDevice">bindWSDevice</button></div>
        <div>{{resbindWSDevice}}</div>
        <div><button @click="unbindWSDevice">unbindWSDevice</button></div>
        <div>{{resunbindWSDevice}}</div>
        <div><button @click="updateRangingFrequency">updateRangingFrequency</button></div>
        <div>{{resupdateRangingFrequency}}</div>
        <div><button @click="setReaderToFree">setReaderToFree</button></div>
        <div>{{ressetReaderToFree}}</div>
        <div><button @click="release">release</button></div>
        <div>{{resrelease}}</div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script>
        document.addEventListener('deviceready', function () {
            new Vue({
                el: '#app',
                data() {
                    return {
                        did: '',
                        freq: 2,
                        resadd: '==============',
                        resinit: '==============',
                        resopenSerialPort: '==============',
                        rescloseSerialPort: '==============',
                        resscanWSDevice: '==============',
                        resbindWSDevice: '==============',
                        resunbindWSDevice: '==============',
                        resupdateRangingFrequency: '==============',
                        ressetReaderToFree: '==============',
                        resrelease: '=============='
                    }
                },
                methods: {
                    add() {
                        let _this = this
                        try {
                            cordova.plugins.ccrfidplugin.add(2, 3, function (res) {
                                _this.resadd = res
                            }, function (err) {
                                _this.resadd = err
                            })
                        } catch (e) {
                            console.log(e)
                        }
                    },
                    init() {
                        let _this = this
                        cordova.plugins.ccrfidplugin.init(function (res) {
                            _this.resinit = res
                        }, function (err) {
                            _this.resinit = err
                        })
                    },
                    openSerialPort() {
                        let _this = this
                        cordova.plugins.ccrfidplugin.openSerialPort(function (res) {
                            _this.resopenSerialPort = res
                        }, function (err) {
                            _this.resopenSerialPort = err
                        })
                    },
                    closeSerialPort() {
                        let _this = this
                        cordova.plugins.ccrfidplugin.closeSerialPort(function (res) {
                            _this.rescloseSerialPort = res
                        }, function (err) {
                            _this.rescloseSerialPort = err
                        })
                    },
                    scanWSDevice() {
                        let _this = this
                        cordova.plugins.ccrfidplugin.scanWSDevice(function (res) {
                            _this.resscanWSDevice = res
                        }, function (err) {
                            _this.resscanWSDevice = err
                        })
                    },
                    bindWSDevice() {
                        let _this = this
                        cordova.plugins.ccrfidplugin.bindWSDevice(this.did, function (res) {
                            _this.resbindWSDevice = res
                        }, function (err) {
                            _this.resbindWSDevice = err
                        })
                    },
                    unbindWSDevice() {
                        let _this = this
                        cordova.plugins.ccrfidplugin.unbindWSDevice(this.did, function (res) {
                            _this.resunbindWSDevice = res
                        }, function (err) {
                            _this.resunbindWSDevice = err
                        })
                    },
                    updateRangingFrequency() {
                        let _this = this
                        cordova.plugins.ccrfidplugin.updateRangingFrequency(this.did, this.freq, function (res) {
                            _this.resupdateRangingFrequency = res
                        }, function (err) {
                            _this.resupdateRangingFrequency = err
                        })
                    },
                    setReaderToFree() {
                        let _this = this
                        cordova.plugins.ccrfidplugin.setReaderToFree(function (res) {
                            _this.ressetReaderToFree = res
                        }, function (err) {
                            _this.ressetReaderToFree = err
                        })
                    },
                    release() {
                        cordova.plugins.ccrfidplugin.release(function (res) {
                            _this.resrelease = res
                        }, function (err) {
                            _this.resrelease = err
                        })
                    }
                }
            })
        })
    </script>
</body>

</html>
